﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoCore.Configuration
{
    /// <summary>
    /// Server配置
    /// </summary>
    public class ServerConfigElement : ConfigurationElement
    {
        /// <summary>
        /// 服务器地址
        /// </summary>
        [ConfigurationProperty("address", IsRequired = true)]
        public string Address
        {
            get
            {
                return (string)this["address"];
            }
            set
            {
                this["address"] = value;
            }
        }

        /// <summary>
        /// 主Host地址
        /// </summary>
        [ConfigurationProperty("mainHosts")]
        public AddressElementCollection MainHostCollection
        {
            get
            {
                return (AddressElementCollection)this["mainHosts"];
            }
        }

        /// <summary>
        /// 服务器性能，按性能比例分发请求数量，默认值1
        /// </summary>
        [ConfigurationProperty("performance", DefaultValue = 1.0)]
        public double Performance
        {
            get
            {
                return (double)this["performance"];
            }
            set
            {
                this["performance"] = (object)value;
            }
        }

        /// <summary>
        /// 心跳周期，单位分钟, 默认5分钟
        /// </summary>
        [ConfigurationProperty("connectPeriod", DefaultValue = 5.0)]
        public double ConnectPeriod
        {
            get
            {
                return (double)this["connectPeriod"];
            }
            set
            {
                this["connectPeriod"] = (object)value;
            }
        }

        /// <summary>
        /// 主Host终结点
        /// </summary>
        [ConfigurationProperty("mainHostEndpoint", IsRequired = false)]
        public string MainHostEndpoint
        {
            get
            {
                return (string)this["mainHostEndpoint"];
            }
            set
            {
                this["mainHostEndpoint"] = (object)value;
            }
        }
    }
}
